import axios from './config'

// 请求拦截
// axios.defaults.withCredentials=true;
axios.interceptors.request.use(function (config) {
    config.params = config.params ? config.params : {};
    if (config.loading) {
        null;
    }

    const timestamp = new Date().getTime()+'';
    return continueDone();
    function continueDone() {
        let accessToken = localStorage.getItem('authorization');
        if (config.method === 'get') {
            config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
        } else if (config.method === 'post') {
            if (config.headers['Content-Type'] === 'multipart/form-data') {
                null;
            } else {
                null;
            }

        }
        config.headers['authorization'] = accessToken;
        config.headers.timestamp = timestamp;
        return config

    }
}, function (error) {
    return Promise.reject(error)
});

// 响应拦截
axios.interceptors.response.use(function (response) {

    response = response.data;
    if (response.code !== 10000) {
        null;
    }

    return response

}, function (error) {

    return Promise.reject(error)
});
export default axios
